package com.papercutting.platform.controller;

import com.papercutting.platform.common.Result;
import com.papercutting.platform.entity.TutorialStep;
import com.papercutting.platform.service.TutorialStepService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 教程步骤控制器
 */
@RestController
@RequestMapping("/api/tutorial-step")
@RequiredArgsConstructor
public class TutorialStepController {
    
    private final TutorialStepService tutorialStepService;
    
    /**
     * 根据教程ID获取步骤列表
     */
    @GetMapping("/list")
    public Result<List<TutorialStep>> getTutorialSteps(@RequestParam Long tutorialId) {
        List<TutorialStep> steps = tutorialStepService.findByTutorialIdOrderByStepNumberAsc(tutorialId);
        return Result.success(steps);
    }
    
    /**
     * 获取步骤详情
     */
    @GetMapping("/{id}")
    public Result<TutorialStep> getTutorialStepDetail(@PathVariable Long id) {
        TutorialStep step = tutorialStepService.findById(id);
        if (step == null) {
            return Result.error(404, "步骤不存在");
        }
        return Result.success(step);
    }
}